<%@page import="java.net.URLEncoder"%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/javascript.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<title>查看地图</title>
<style type="text/css">
body,html,#allmap {
	width: 100%;
	height: 100%;
	overflow: hidden;
	margin: 0;
}

#l-map {
	height: 100%;
	width: 73%;
	float: left;
	border-right: 2px solid #bcbcbc;
}

#r-result {
	height: 100%;
	width: 25%;
	float: left;
}

.area_span {
	color: #004499;
	margin-right: 10px;
	cursor: pointer;
}

.area_span_select {
	color: #ff812d;
	margin-right: 10px;
	cursor: pointer;
}

.wy_type_selected {
	color: #ff812d;
	line-height: 20px;
	cursor: pointer;
}

.wy_type_normal {
	color: #004499;
	line-height: 20px;
	cursor: pointer;
}

.price_type_selected {
	color: #ff812d;
	line-height: 20px;
	cursor: pointer;
}

.price_type_normal {
	color: #004499;
	line-height: 20px;
	cursor: pointer;
}

.status_selected{
	color: #ff812d;
	line-height: 20px;
	cursor: pointer;
}

.status_normal{
	color: #004499;
	line-height: 20px;
	cursor: pointer;
}

.land_selected {
	color: #ff812d;
	line-height: 20px;
	cursor: pointer;
}

.land_normal {
	color: #004499;
	line-height: 20px;
	cursor: pointer;
}

</style>
<script type="text/javascript"
	src="http://api.map.baidu.com/api?v=1.5&ak=FD619b3a912624d6d79233bbf0709528"></script>
<script type="text/javascript" src="js/DistanceTool_min.js"></script>
<script type="text/javascript" src="js/jquery.PrintArea.js"></script>
<link rel="stylesheet" type="text/css" href="css/PrintArea.css">
<script type="text/javascript" src="js/SearchInfoWindow_min.js"></script>
<link rel="stylesheet" type="text/css"
	href="http://api.map.baidu.com/library/SearchInfoWindow/1.5/src/SearchInfoWindow_min.css">
<script type="text/javascript">
    	var viewType='${viewType}';
    	var type='${type}';
    	var ltype='${ltype}';
    	var point;
    	var map;
    	var content="${content}";
    	var area; 
    	var isTdChecked=true;
    	var isLpChecked=false;
    	var markname='${markerName}';
    	var icon=new BMap.Icon('images/marker/'+markname,new BMap.Size(36, 36),
    		 { anchor: new BMap.Size(18, 18)});
		$(document).ready(function(e) {
            map = new BMap.Map("allmap");            // 创建Map实例
			map.enableScrollWheelZoom();  //启用滚轮放大缩小
			map.enableContinuousZoom();    // 开启连续缩放效果
			map.enableInertialDragging();// 开启惯性拖拽效果
			map.addControl(new BMap.NavigationControl());     
            map.addControl(new BMap.ScaleControl());
			
			if(viewType=='loc'){//定位
				var lng=content.split("*")[0];
        		var lat=content.split("*")[1];
        		var title=content.split("*")[2];
        		var landType=content.split("*")[3];
        		var strPoints=content.split("*")[4];
        		var stype=content.split("*")[5];
        		var context='<div style="margin:0;line-height:20px;padding:2px;">'+
						content.split("*")[6]+'</div>';
            	if(type=='1'){ //市区统计
					height=250;
            	}else if(type=='2'){ //行政区统计
            		height=150;
            	}else if(type=='3'){ //土地相关
					if(ltype=='1'){
						height=150;
					}else if(ltype=='2'){
						height=170;
					}else{
						height=200;
					}
            	}
            	point = new BMap.Point(parseFloat(lng),parseFloat(lat));
        		var opts = {
			  		width : 300,     // 信息窗口宽度
			  		height: height,     // 信息窗口高度
			  		title : title,  // 信息窗口标题
			  		panel  : "panel",         //检索结果面板
  					enableAutoPan : true,     //自动平移
  					searchTypes   :[
  						BMAPLIB_TAB_SEARCH,   //周边检索
  						BMAPLIB_TAB_TO_HERE,  //到这里去
  						BMAPLIB_TAB_FROM_HERE //从这里出发
  					]
				} ;
				var marker;
				var searchInfoWindow = new BMapLib.SearchInfoWindow(map,context,opts);
				if(landType==1){
					marker = new BMap.Marker(point,{icon:icon});
					marker.addEventListener("click",function(){
    					searchInfoWindow.open(marker);
    				});
				}else{
					var points=strPoints.split("|");
					var pts=[];
					for(var j=0;j<points.length;j++){
						var str=points[j].split(",");
						var pt=new BMap.Point(str[0],str[1]);
						pts.push(pt);
					}
					marker=new BMap.Polygon(pts,{strokeColor:"blue",fillColor:"red", strokeWeight:2, strokeOpacity:0.2});
					marker.addEventListener("click",function(){
    					searchInfoWindow.open(new BMap.Point(lng, lat));
    				});
				}
    			map.addOverlay(marker);	
    			map.centerAndZoom(point,16);
            }else{
            	map.centerAndZoom('${ecity.name}');
            	var url="landAction_getAjaxLand?landForm=&t="+Math.random();
    
    			$.post(encodeURI(url),null,function(data){
       				createMap(data);
    			});
            }
            
            area=$("#comArea").val();
            
            $("#comArea").combobox({
				onChange:function(newValue,oldValue){  
					area=newValue;
					search();
				}  
			});
            
      		$(".wy_type_normal").click(function(){
        		$(".wy_type_selected").removeClass("wy_type_selected").addClass("wy_type_normal");
        		$(this).removeClass("wy_type_normal").addClass("wy_type_selected");
        		search();
     		});
     
      		$(".wy_type_selected").click(function(){
        		$(".wy_type_selected").removeClass("wy_type_selected").addClass("wy_type_normal");
        		$(this).removeClass("wy_type_normal").addClass("wy_type_selected");
        		search();
     		});
     	
     		$(".price_type_normal").click(function(){
        		$(".price_type_selected").removeClass("price_type_selected").addClass("price_type_normal");
        		$(this).removeClass("price_type_normal").addClass("price_type_selected");
        		search();
     		});
     
      		$(".price_type_selected").click(function(){
        		$(".price_type_selected").removeClass("price_type_selected").addClass("price_type_normal");
        		$(this).removeClass("price_type_normal").addClass("price_type_selected");
        		search();
     		});
     
      		$(".land_normal").click(function(){
        		$(".land_selected").removeClass("land_selected").addClass("land_normal");
        		$(this).removeClass("land_normal").addClass("land_selected");
        		search();
     		});
     
      		$(".land_selected").click(function(){
        		$(".land_selected").removeClass("land_selected").addClass("land_normal");
        		$(this).removeClass("land_normal").addClass("land_selected");
        		search();
     		});
     		
     		$(".status_normal").click(function(){
        		$(".status_selected").removeClass("status_selected").addClass("status_normal");
        		$(this).removeClass("status_normal").addClass("status_selected");
        		search();
     		});
     
      		$(".status_selected").click(function(){
        		$(".status_selected").removeClass("status_selected").addClass("status_normal");
        		$(this).removeClass("status_normal").addClass("status_selected");
        		search();
     		});
  
    		var myDistanceToolObject = new BMapLib.DistanceTool(map, {lineStroke : 2});
    		$("#btnDistance").bind('click',function(){
    			myDistanceToolObject.open();
    		});
    		
    		myDistanceToolObject.addEventListener("drawend", function(e) {  
    			 myDistanceToolObject.close();
    		});
    		
    		$("#btnScrnCut").bind('click',function(){
    			try{
					var objsc = new ActiveXObject("ScrnCut.MainCtl");
					if(objsc.cut()){ //截屏并发送
       					//alert(objsc.GetImg()); //截屏数据 BASE64 String 发送回服务器端解码后得到图片
    				}
				}catch(e){
					if(confirm("您还没有安装截屏插件\n\n现在下载安装吗？")){
              			open("iesc.msi");
        			}
				}
    		});
    		
    		$("#btnPrint").bind("click",function(){
    			$("div#myPrintArea").printArea();
    		});
        });
        function search(){
    		
    		var wy_type=$($(".wy_type_selected")[0]).html();
    		var price=$($(".price_type_selected")[0]).html();
    		var landType=$($(".land_selected")[0]).html();
    		var statusStr=$($(".status_selected")[0]).html();
    
    		var url="";
    		if(isTdChecked){
    			var params="?landForm.area="+area+"&";
    			landType=getLandType(landType);
    			params+="landForm.landType="+landType+"&";
    			url="landAction_getAjaxLand"+params+"t="+Math.random();
    		}else{
    			var status=getStatus(statusStr);
    			var params="?landForm.status="+status+"&";
    			params+="landForm.area="+area+"&";
    			wy_type=getWyType(wy_type);
     			params+="landForm.wy_type="+wy_type+"&";
     			price=getPrice(price);
     			params+="landForm.price="+price+"&";
     			url="mapAction_getAjaxLand"+params+"t="+Math.random();
    		}
    		
    		map.clearOverlays();
    		
    		$.post(encodeURI(url),null,function(data){
       			createMap(data);
    		});
    
  		}
  
  		function createMap(data){
     		datas=data.split("#");
     		$.each(datas,function(index,val){
        		var lng=val.split("*")[0];
        		var lat=val.split("*")[1];
        		var title=val.split("*")[2];
        		var landType=val.split("*")[3];
        		var strPoints=val.split("*")[4];
        		var stype=val.split("*")[5];
        		var context=val.split("*")[6];
        		var iconName=val.split("*")[7];
        		point= new BMap.Point(lng, lat);
        		icon=new BMap.Icon('images/marker/'+iconName,new BMap.Size(36, 38),
    				 { anchor: new BMap.Size(18, 18)});
        		var h;
        		if(stype=='1'){
        			h=150;
        		}else if(stype=='2'){
        			h=170;
        		}else if(stype=='3'){
        			h=200;
        		}else if(stype=='4'){
        			h=200;
        		}else{
        			h=150;
        		}
        		var opts = {
			  		width : 300,     // 信息窗口宽度
			  		height: h,     // 信息窗口高度
			  		title : title,  // 信息窗口标题
			  		panel  : "panel",         //检索结果面板
  					enableAutoPan : true,     //自动平移
  					searchTypes   :[
  						BMAPLIB_TAB_SEARCH,   //周边检索
  						BMAPLIB_TAB_TO_HERE,  //到这里去
  						BMAPLIB_TAB_FROM_HERE //从这里出发
  					]
				} ;
				var marker;
				var searchInfoWindow = new BMapLib.SearchInfoWindow(map,context,opts);
				if(landType==1){
					marker = new BMap.Marker(point,{icon:icon});
					marker.addEventListener("click",function(){
    					searchInfoWindow.open(marker);
    				});
				}else{
					var points=strPoints.split("|");
					var pts=[];
					for(var j=0;j<points.length;j++){
						var str=points[j].split(",");
						var pt=new BMap.Point(str[0],str[1]);
						pts.push(pt);
					}
					marker=new BMap.Polygon(pts,{strokeColor:"blue",fillColor:"red", strokeWeight:2, strokeOpacity:0.2});
					marker.addEventListener("click",function(){
    					searchInfoWindow.open(new BMap.Point(lng, lat));
    				});
				}
				
		 		
    			map.addOverlay(marker);	
     		});
  
  		}
  		
  		function getStatus(value){
  			if(value=="在售"){
  				return "1";
  			}else if(value=="待售"){
  				return "2";
  			}else if(value=="售完"){
  				return "3";
  			}else if(value=="在租"){
  				return "4";
  			}else{
  				return "-1";
  			}
  		}
  
  		function getWyType(type){
    		if(type=="住宅")
      			return "1";
     		else if(type=="别墅")
       			return "2";
       		else if(type=="商铺")
       			return "3";
       		else if(type=="写字楼")
        		return "4";
        	else if(type=="经济适用房")
        		return "5";
        	else
         		return "6";
         }
  
  		function getPrice(price){
 
    		if(price=="4千以下")
     			return "<4000";
     		else if(price=="4千-5千")
     			return "between 4000 and 5000";
     		else if(price=='5千-7千')
     			return "between 5000 and 7000";
     		else if(price=="7千以上")
     			return " >7000";
     		else 
     			return "1";
  		}
  
  		function getLandType(landType){
    		if(landType=='用地计划')
    			return 1;
    		else if(landType=='土地出让')
    			return 2;
    		else if(landType=='土地成交')
     			return 3;
     		else return 4;
  		}
  		
  		function checkChange(){
  			search();
  		}
  		
  		function checktd(){
  			if(isTdChecked){
  				isTdChecked=false;
  				isLpChecked=true;
  				$("#cbtd").attr("checked",false);
  				$("#cblp").attr("checked",true);
  			}else{
  				isTdChecked=true;
  				isLpChecked=false;
  				$("#cbtd").attr("checked",true);
  				$("#cblp").attr("checked",false);
  			}
  			search();
  		}
  		
  		function checklp(){
  			if(isLpChecked){
  				isTdChecked=true;
  				isLpChecked=false;
  				$("#cbtd").attr("checked",true);
  				$("#cblp").attr("checked",false);
  			}else{
  				isTdChecked=false;
  				isLpChecked=true;
  				$("#cbtd").attr("checked",false);
  				$("#cblp").attr("checked",true);
  			}
  			search();
  		}
	</script>
</head>
<body class="easyui-layout">
	<div data-options="region:'east',collapsed:false"
		style="width:200px;padding:10px;" class="Noprint">
		<div style="height:50px">
			<input id="btnDistance" type="button" value="测距" /> <input
				id="btnScrnCut" type="button" value="截图" /> <input id="btnPrint"
				type="button" value="打印" />
		</div>
		<div>
			<hr style="border:none;border-top:1px solid #def2fe">
			<div>
				<label style="margin-right: 10px;">行政区域</label><select id="comArea"
					class="easyui-combobox" name="comArea"
					style="width:100px; text-align:center;">
					<option value="-1">--区域不限--</option>
					<c:forEach items="${regions}" var="region">
						<option value="${region.id }">${region.name }</option>
					</c:forEach>
				</select>
			</div>
			<hr style="border:none;border-top:1px solid #def2fe">
			
			<div><input id="cbtd" type="radio" checked="checked" onclick="checktd();"/>土地相关</div>
			<div style="border: 1px solid #77c0f1;padding: 5px;margin-left: 10px; margin-bottom: 5px;margin-top: 3px;">
				<div style="margin-top:3px;">
				土地：  <span class="land_selected">不限</span><br />
				<span class="land_normal">用地计划</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				<span class="land_normal">土地出让</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
				<span class="land_normal">土地成交</span>
				</div>
			</div>
			
			<hr style="border:none;border-top:1px solid #def2fe">
			<div><input id="cblp" type="radio" onclick="checklp();"/>楼盘相关</div>
				<div style="border: 1px solid #77c0f1;padding: 5px;margin-left: 10px;margin-bottom: 5px;margin-top: 3px;">
					<div style="margin-top:3px">
					物业类型：&nbsp;&nbsp;<span class="wy_type_selected">不限</span><br/>
					<span class="wy_type_normal">住宅</span> &nbsp;&nbsp; 
					<span class="wy_type_normal">经济适用房</span>&nbsp;&nbsp;
					<span class="wy_type_normal">别墅</span><br /> 
					<span class="wy_type_normal">写字楼</span>&nbsp;&nbsp; 
					<span class="wy_type_normal">商铺</span>
				</div>
				<hr style="border:none;border-top:1px solid #def2fe">
				<div style="margin-top:3px">
					价格：&nbsp;&nbsp;<span class="price_type_selected">不限</span>&nbsp;&nbsp;
					<br /> <span class="price_type_normal">4千以下</span>&nbsp;&nbsp;&nbsp;&nbsp;
					<span class="price_type_normal">4千-5千</span><br/>
					<span class="price_type_normal">5千-7千</span>&nbsp;&nbsp;&nbsp;&nbsp;
					<span class="price_type_normal">7千以上</span> <br/> 
					<span>单位(元/m<sup>2</sup>)</span>
				</div>
				<hr style="border:none;border-top:1px solid #def2fe">
				<div style="margin-top:3px">
					楼盘状态：&nbsp;&nbsp;<span class="status_selected">不限</span>&nbsp;&nbsp; <br />
					<span class="status_normal">在售</span>&nbsp;&nbsp;
					<span class="status_normal">待售</span>&nbsp;&nbsp;
					<span class="status_normal">售完</span>&nbsp;&nbsp;
					<span class="status_normal">在租</span>&nbsp;&nbsp;
				</div>
			</div>
		</div>
	</div>
	<div id="myPrintArea" data-options="region:'center'">
		<div id="allmap"></div>
	</div>
	<div id="panel" style="position:absolute;"></div>
</body>
</html>
